<?php


namespace app\cms\admin\controller;


use app\cms\dto\companyInfo;
use app\cms\dto\friendInfo;
use app\cms\dto\navInfo;
use app\cms\dto\siteInfo;
use app\cms\model\companyModel;
use app\cms\model\friendModel;
use app\cms\model\navModel;
use app\cms\model\siteModel;
use iflow\auth\Authorize\AuthAnnotation;
use iflow\Response;
use iflow\Router\Controller;
use iflow\Router\implement\Request\{ PostMapping, DeleteMapping };

#[Controller('%cmsAdmin%/info')]
class info
{

    /**
     * 更新站点信息
     * @param siteInfo|null $siteInfo
     * @return Response
     */
    #[AuthAnnotation('change', 'siteInfoWrite')]
    #[PostMapping]
    public function updateSiteInfo(?siteInfo $siteInfo = null): Response
    {
        return (new siteModel) -> updateSiteInfo($siteInfo);
    }

    /**
     * 更新企业信息
     * @param companyInfo|null $companyInfo
     * @return Response
     */
    #[AuthAnnotation('change', 'companyWrite')]
    #[PostMapping]
    public function updateCompanyInfo(?companyInfo $companyInfo = null): Response
    {
        return companyModel::updateCompanyInfo($companyInfo);
    }

    /**
     * 添加导航栏
     * @param navInfo|null $navInfo
     * @return Response
     */
    #[AuthAnnotation('change', 'NavWrite')]
    #[PostMapping]
    public function addNavInfo(?navInfo $navInfo = null): Response
    {
        return navModel::addNavInfo($navInfo);
    }

    /**
     * 更新导航栏
     * @param navInfo|null $navInfo
     * @return Response
     */
    #[AuthAnnotation('change', 'NavWrite')]
    #[PostMapping]
    public function upDateNavInfo(?navInfo $navInfo = null): Response
    {
        return navModel::changeNavItems($navInfo);
    }

    /**
     * 删除栏目列表
     * @param int $nav_id
     * @return Response
     */
    #[AuthAnnotation('change', 'NavWrite')]
    #[DeleteMapping('del_nav_info/<[0-9]{1,8}:nav_id>')]
    public function deleteDateNavInfo(int $nav_id = 0): Response
    {
        return (new \app\cms\model\navModel) -> deleteNav($nav_id);
    }

    /**
     * 添加友链
     * @param friendInfo|null $friendInfo
     * @return Response
     */
    #[AuthAnnotation('change', 'friendWrite')]
    #[PostMapping]
    public function addFriend(?friendInfo $friendInfo = null): Response
    {
        return friendModel::addFriend($friendInfo);
    }

    /**
     * 删除友链
     * @param int $site_id
     * @return Response
     */
    #[AuthAnnotation('change', 'friendWrite')]
    #[DeleteMapping('delete_friend_info/<?:site_id>')]
    public function deleteFriendInfo(int $site_id = 0): Response
    {
        return friendModel::deleteFriend($site_id);
    }


}